﻿using Microsoft.AspNetCore.Http;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using UtilsCache;
using UtilsORM;
using UtilsORM.MySqlData;

////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotDeviceTaskPlainCache
    {


        EFYihongIotContext ef = new EFYihongIotContext();


        public iot_device_task_plain getPlainCache(string tpguid)
        {
            // UtilRedisNewLife UtilRedisNewLife = UtilRedisNewLife;


            iot_device_task_plain plain = UtilMemoryCacheHelper.get<iot_device_task_plain>("iot_device_task_plaintpguid" + tpguid);
            if (plain == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                plain = ef.iot_device_task_plain.Where(c => c.tp_guid == tpguid && c.tp_status == 0 && c.tp_auto_run == 0).FirstOrDefault();
                UtilMemoryCacheHelper.set("iot_device_task_plaintpguid" + tpguid, plain, 1);
            }
            return plain;
        }

        public List<iot_device_task_plain_item> getPlainItemCache(string tpguid)
        {
            //UtilRedisNewLife UtilRedisNewLife = UtilRedisNewLife;

            List<iot_device_task_plain_item> plainitem = UtilMemoryCacheHelper.get<List<iot_device_task_plain_item>>("iot_device_task_plain_itemtpguid" + tpguid);
            if (plainitem == null)
            {
                EFYihongIotContext ef = new EFYihongIotContext();
                plainitem = ef.iot_device_task_plain_item.Where(c => c.tpi_tp_guid == tpguid && c.tpi_status == 0).OrderBy(c => c.tpi_order).ToList();
                UtilMemoryCacheHelper.set("iot_device_task_plain_itemtpguid" + tpguid, plainitem, 1);
            }
            return plainitem;
        }

    }
}
